package com.hmall.item.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import jdk.nashorn.internal.ir.RuntimeNode;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import rx.internal.util.unsafe.MpmcArrayQueue;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;



    @GetMapping("/list")
    public PageDTO list  (@RequestParam("page") Integer page, @RequestParam("size") Integer size) {
         log.info("page" +page ,size);

        return   itemService.getlist(page,size);

    }
    //根据id查询
    @GetMapping("/{id}")
    public Item getId (Long id){

        return  itemService.getById1(id);
    }
    //新增
    @PostMapping()
    public Boolean additem( @RequestBody Item item){



    return itemService.save1( item);

    }
    //上架下架
    @PutMapping("/status/{id}/{status}")
public void shangjia  (@PathVariable Long id, @PathVariable Integer status){
           itemService.update1(id,status);
    }
//修改商品
    @PutMapping
    public  void update(@RequestBody Item item){
             itemService.getupdate(item);

    }
    //根据di删除
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id){
        itemService.getdelete(id);

    }

}
